package com.cicc.beergamevirtualsimulationsystem.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cicc.beergamevirtualsimulationsystem.entity.RecordEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;
@Mapper
public interface RecordMapper extends BaseMapper<RecordEntity> {




    //主持人数据展示折线图
    @Select("SELECT user_role AS role, " +
            "pre_receiver_total, " +
            "deliver_total, " +
            "user_name AS userName, " +
            "period " +
            "FROM record " +
            "WHERE room_id = #{roomId} " +
            "ORDER BY period ASC")
    List<RecordEntity> selectAggregatedData(String roomId);


    //主持人数据展示柱状图
    @Select("SELECT user_role AS role, " +
            "       user_id AS userId, " +
            "       user_name AS userName, " +
            "       SUM(profit) AS profit, " +
            "       SUM(pre_receiver_total_cost) AS preReceiverTotalCost, " +
            "       SUM(inventory_cost) AS inventoryCost, " +
            "       SUM(deferred_delivery_cost) AS deferredDeliveryCost " +
            "FROM record " +
            "WHERE room_id = #{roomId} " +
            "GROUP BY user_role, user_id, user_name")
    List<RecordEntity> selectTotalOrderByRole(String roomId);


    //玩家利润总数
    @Select("SELECT SUM(profit) AS profit FROM record WHERE room_id = #{roomId} and user_id=#{userId} and user_role =#{userRole} ")
    Integer selectProfit(@Param("roomId") String roomId,@Param("userId") String userId,@Param("userRole") Integer userRole);


    //主持人游戏界面展示全部玩家的利润数据
    @Select("SELECT user_role AS role, user_name, SUM(profit) AS profit " +
            "FROM record " +
            "WHERE room_id = #{roomId} " +
            "GROUP BY user_role, user_name " +
            "ORDER BY profit ASC")
    List<RecordEntity> selectAllPlayerProfit(String roomId);
}
